home *** CD-ROM | disk | FTP | other *** search
/ Aminet 23 / Aminet 23 (1998)(GTI - Schatztruhe)[!][Feb 1998].iso / Aminet / text / edit / Smartindent.lha / Smartindent / Source / test_correct.c < prev    next >
C/C++ Source or Header  |  1997-12-14  |  7KB  |  302 lines

  1. /*    Don't think about this code...
  2. **    It is nonsense, but shows several posibilities than can occure in real
  3. **    live. When you can think of anything else to be tested, please mail an
  4. **    according piece of code to me.
  5. **
  6. **    The file test_correct.c is indented as smartindent *should* indent it.
  7. **    The file test_input.c   is completely wrong indented and the input file
  8. **    for 'smake test' (see below).
  9. **
  10. **    However not everything works right now as it should.
  11. **    Do 'smake test' in order to test correct indention process.
  12. **    For this you will have to have a 'diff' utility in your path.
  13. **
  14. **    Some lines contain a comment      / * !!! BUG !!! * /
  15. **    (no spaces between * and / and before and after BUG -
  16. **    it cannot be printed here verbosely, otherwise the semantic parser
  17. **    could have strange effects on this comment line...)
  18. **    Guess on which lines...
  19. **
  20. **    Note that not everything can be tested that way.
  21. **    For example, when a line is indented more or less than it should be
  22. **    and *only* the next lines are to be indented, it will take the (wrong)
  23. **    indention of the line above and use it instead of the calculated value.
  24. **    I found that better for daily use than obductrinating calculated
  25. **    indentions.
  26. **
  27. **    e.g. the code       will be block indented
  28. **         {              {
  29. **         blafoo;            blafoo;
  30. **           asdf;            asdf;
  31. **         }              }
  32. **    but when you only indent the line 'asdf;', you will get
  33. **         {
  34. **         blaffo;
  35. **         asdf;
  36. **         }
  37. **
  38. **    Matthias Hopf <mshopf@informatik.uni-erlangen.de>
  39. */
  40.  
  41. /* first column comment */
  42.     /* indented comment */
  43. /*    Mulitline w/o starter, begining first line.
  44.       this is second line
  45.  
  46.       Line after empty line
  47. */
  48. /*    Mulitline w/o starter, begining first line.
  49.       this time end of comment in last text line. */
  50. /*
  51.    Mulitline w/o starter, begining first empty line.
  52.    this is second line
  53. */
  54. /*
  55.  *   Mulitline w '*' starter, begining first empty line.
  56.  *  this is second line
  57.  */
  58. /*   Mulitline w '*' starter, begining first line.
  59.  *   this time end of comment in last text line. */
  60. /*
  61. **   Mulitline w '**' starter, begining first empty line.
  62. **  this is second line
  63. */
  64. /*
  65.  *   Mulitline mixed mode.
  66.  This may have strange results.
  67.  
  68.  But who cares, anyone using this is mad anyway.
  69. **   Don't you think so?
  70. */
  71.  
  72. /* */ /* double comment */ /* !!!BUG!!! */
  73. /*                                               */ /* empty comment */ /* !!!BUG!!! */
  74. //       asdf                     /* spaced first word in // comment */ /* !!!BUG!!! */
  75.  
  76. #if asdf
  77. #  error
  78. #endif
  79.  
  80. #define macro qwer \
  81.           blafoo \
  82.           ssss
  83. asdf;
  84. #define macro(x) qwer \
  85.          blafoo \
  86.          sss
  87. asdf;
  88. #  define macro(x) \
  89.   qwer \
  90.   asdf
  91. # define \
  92.      sss
  93. asdf;
  94.  
  95. struct test {                           /* in-line comment */
  96.     int i;                              // C++ comment
  97.     char v [
  98.          10];
  99. }
  100. asdf;
  101.  
  102. extern int mm =                         /* This comment disturbs the next line */
  103.         d;                      /* !!!BUG!!! */
  104. extern int i,
  105.        j =                          /* !!!BUG!!!*/ /* This line should be indented under 'i' */
  106.         test * 5 +
  107.         77 - asdf
  108.         + nix,
  109.        k = (
  110.          asdf
  111.            ) + (
  112.              qwer);
  113.  
  114. void
  115. function (x,y,z)
  116. {   blafoo;                             /* !!!BUG!!! */ /* This code should be indented at block level. */
  117.     struct TableElem
  118.     {
  119.     TableElem *next;
  120.     int asdf;
  121.     void (*func) (int, char *, unsigned
  122.               long);
  123.     int bla,
  124.         foo;                        /* !!!BUG!!! */ /* Should be indented under 'bla'. Currently Cont_Level is used. */
  125.     }
  126.     i =
  127.     {
  128.     0,
  129.     1,
  130.     adsf ? qwer :
  131.            asdf,
  132.     (j == qwer),
  133.     'x',
  134.     "This is a String"
  135.     " even more string"
  136.     }
  137.     ;                                   /* !!!BUG!!! *//* Oops.. Strange side effect... :-( */
  138.     struct TableElem i = {
  139.     0,
  140.     1
  141.     } ;
  142.  
  143.     blafoo (x);
  144.  
  145.     cout >> "Hello "
  146.      >> "World!";
  147.  
  148.     Temp::Temp(adf);
  149.  
  150.     i = (asdf ?
  151.         qewwew :
  152.         qeww );
  153.     i = asdf ?
  154.            qewwew :
  155.            qeww;
  156.     i = asdf ?
  157.            qewwew
  158.            : qeww;
  159.     i = j =
  160.     k;
  161.     i = (j =
  162.          k);
  163.     i +=
  164.      k;
  165.     i &&=
  166.       k;
  167.  
  168.     if (i ==
  169.     j)
  170.     bla;
  171.     if (i <=
  172.     j)
  173.     bla;
  174.     if ( (i =
  175.           j) )
  176.     bla;
  177.     if ( (i +=
  178.            j) )
  179.     bla;
  180.     if ( (i &&=
  181.         j) )
  182.     bla;
  183.  
  184.     if ( (i =
  185.           j ==
  186.           k) )
  187.     bla;
  188.  
  189.     if ( (i = j) &&
  190.      k == l ||
  191.      m !=
  192.      o)
  193.     bla;
  194.  
  195.   asdf:
  196.     bla;
  197.  
  198.     TableElem():next(0),elem(0){}
  199.     foo;
  200.  
  201.     switch (c) {
  202.     bla;
  203.       case 0:
  204.     foo;
  205.       default:
  206.     }
  207.  
  208.     for (asdf;
  209.      qwer;
  210.      ttt)
  211.     i++;
  212.     bla;
  213.     while (1)
  214.     i++;
  215.     bla;
  216.  
  217.     while (1) i++;
  218.     bla;
  219.  
  220.     if (x) asdf;
  221.     else   qwer;
  222.     bla;
  223.     if (x) if (y) asdf;
  224.     else qwer;
  225.     bla;
  226.  
  227.     if (x)
  228.     if (y)
  229.         a;
  230.     else
  231.         b;
  232.     else
  233.     c;
  234.  
  235.     if (x)
  236.     if (y)
  237.     {
  238.         if (z)
  239.         a;
  240.     }
  241.     else
  242.     {
  243.         d;
  244.     }
  245.     else
  246.     f;
  247.  
  248.     if (a)
  249.     switch (b) {
  250.     }
  251.     asdf;                               /* !!!BUG!!! */ /* thought to be still inside block */
  252.     bla;
  253.  
  254.     if (a)
  255.     yxcv;
  256.     else
  257.     for (;;)
  258.         asdf;
  259.     qwer;                               /* !!!BUG!!! */ /* thought to be still inside block */
  260.     bla;
  261.  
  262.     if (a)
  263.     try {                           /* don't know whether this will ever be correct, because it is mad! */
  264.         asdf();
  265.     }
  266.     catch (x) {                     /* err, this is correctly indeted by accident :] */
  267.         bla;                    /* !!!BUG!!! */ /* should be gone by correcting the above ones */
  268.     }                               /* !!!BUG!!! */ /* should be gone by correcting the above ones */
  269.     catch (y)                       /* err, this is again correctly indented by accident :] */
  270.     {                               /* !!!BUG!!! */ /* should ... */
  271.         foo;                        /* dto. */
  272.     }                               /* dto. */
  273.     qwer;                               /* !!!BUG!!! */ /* correlated to the above ones */
  274.     blubs;
  275.  
  276. }
  277.  
  278. /* C++ errors - Henning Tietgens <hawk@informatik.uni-bremen.de> */
  279.  
  280. class test_child : public test
  281. {
  282.   public:
  283.     void testing();
  284. };
  285.  
  286. void test::testing()
  287. {
  288.     cout << "Test"
  289.      << endl;
  290. }
  291.  
  292. /* Nested comments error - Marty King <mking@atl.com> */
  293. /* Note: default is now unnested comments (compile-time option, see semantics_c.c) */
  294. /* first level comment
  295.    /* second level comment
  296.    void main() {}
  297. */
  298. void test() {}                          /* this would be thought to be a comment when using nested comments */
  299. */
  300. void main() {}                          /* outside comments */
  301.  
  302.